/*
 * @author: wizardc
 */

using UnityEngine;

namespace Dou.ScreenController
{
    /// <summary>
    /// SetActive 支持横竖屏切换的适配器
    /// </summary>
    public class ActiveAdapter : MonoBehaviour, IUIAdapter
    {
        [HideInInspector]
        public UIAdapterBool isActive;
        
        private GameObject _gameObject;
        
        void Awake()
        {
            _gameObject = gameObject;
            ScreenUIAdapterMgr.instance.AddAdapter(this);
        }
        
        public void RefreshAdapter(int uiScreenMode, int uiFineTuningMode)
        {
            if (isActive.GetValue(uiScreenMode, uiFineTuningMode, out var result))
            {
                _gameObject.SetActive(result);
            }
        }
        
#if UNITY_EDITOR

        public void RefreshAdapterInEditor(int uiScreenMode, int uiFineTuningMode)
        {
            if (isActive.GetValue(uiScreenMode, uiFineTuningMode, out var result))
            {
                gameObject.SetActive(result);
            }
        }
        
#endif
        
        void OnDestroy()
        {
            ScreenUIAdapterMgr.instance.RemoveAdapter(this);
        }
    }
}
